<?php
namespace apps\common\models;
if( ! APP_ROOT  ) return 'Direct Access Deny!';

use Phalcon\Mvc\Model;
use enums\SystemEnums;

/**
 * 讲解员申请认证材料表
 * @author Carey
 * @date 2016-10-19
 */
class NarratorApplyPics extends Model
{
    public $id;
    
    public $create_time;
    
    public $delsign;
    
    public $descr;
    
    public $filename;
    
    public $size;
    
    public $bucket;
    
    public $object;
    
    public $type;
    
    public $assets_id;
    
    public $cdn_url;
    
    public $img_type;
    
    public $narr_id;
    
    public function initialize()
    {
        $this->useDynamicUpdate( true );
        
        $this->setSource( 'bwyt_narrator_apply_pics' );
    }
    
    
    /**
     * 根据 assets_id 删除图片
     * @param unknown $uid
     * @param unknown $asstetsid
     * @return boolean
     */
    public function delbyAssetsId( $uid, $asstetsid )
    {
        if( !$asstetsid )
            return false;
    
        $where = array(
            'conditions'=> 'delsign=:del: and assets_id=:assetsid:',
            'bind'      => array( 'del' => SystemEnums::DELSIGN_NO, 'assetsid' => $asstetsid ),
        );
        if( $uid )
        {
            $where[ 'conditions' ] .= ' and narr_id=:uid: ';
            $where[ 'bind' ][ 'uid' ] = $uid;
        }
        $list = self::find( $where );
        if( $list && count( $list ) > 0 )
        {
            foreach ( $list as $row )
            {
                if( false == $row->delete() )
                    return false;
            }
    
            return true;
        }
        else
            return false;
    
    }
    
}

?>